/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cheetah.sisal.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author edoardo
 */
public class Database {
    
    static final ResourceBundle rb = ResourceBundle.getBundle("org.cheetah.sisal.etc.sisal");

    static {
        try {
            Class.forName(rb.getString("database.driver"));
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }

    }
    public static Connection getConnection(){
        Connection con=null;
        try {
            con = DriverManager.getConnection(rb.getString("database.url"), rb.getString("database.username"),rb.getString("database.password"));
        } catch (SQLException ex) {
            Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
        }
        return con;
    }
    
    public static PreparedStatement getPreparedStatement(Connection con,String sql){
        try {
            return con.prepareStatement(sql);
        } catch (SQLException ex) {
            return null;
        }
    }
    
    public static String getSql(String property){
        return rb.getString(property);
    }
    
}
